﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace RDIFramework.WebApp.Modules
{
    using RDIFramework.BusinessEntity;

    public partial class UserAdmin : BasePage
    {
        DataTable DTUser = new DataTable(PiUserTable.TableName);

        /// <summary>
        /// 添加用户
        /// </summary>
        private bool permissionAdd = false;

        /// <summary>
        /// 编辑用户
        /// </summary>
        private bool permissionEdit = false;

        /// <summary>
        /// 设置密码
        /// </summary>
        private bool permissionSetPassword = false;

        /// <summary>
        /// 导出数据
        /// </summary>
        private bool permissionExport = false;

        /// <summary>
        /// 删除用户
        /// </summary>
        private bool permissionDelete = false;


        /// <summary>
        /// 
        /// 权限域编号(按权限管理范围来列出数据才可以，只能管理这个范围的数据)
        /// 
        /// </summary>
        public string PermissionItemScopeCode = "Resource.ManagePermission";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.GetPermission();
                //this.BindGrid();
            }
        }

        public override string BuildToolBarButtons()
        {
            StringBuilder sb = new StringBuilder();
            string linkbtn_template = "<a id=\"a_{0}\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"{1}\"  {2} title=\"{3}\">{4}</a>";
            sb.Append("<a id=\"a_refresh\" class=\"easyui-linkbutton\" style=\"float:left\"  plain=\"true\" href=\"javascript:;\" icon=\"icon-reload\"  title=\"重新加载\">刷新</a> ");
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "add", "icon-user_add", permissionAdd ? "" : "disabled=\"True\"", "添加用户", "添加"));
            sb.Append(string.Format(linkbtn_template, "edit", "icon-user_edit", permissionEdit ? "" : "disabled=\"True\"", "修改用户", "修改"));
            sb.Append(string.Format(linkbtn_template, "delete", "icon-user_delete", permissionDelete ? "" : "disabled=\"True\"", "删除用户", "删除"));
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "editpassword", "icon-user_key", permissionSetPassword ? "" : "disabled=\"True\"", "设置选中用户密码", "设置密码"));
            sb.Append("<div class='datagrid-btn-separator'></div> ");
            sb.Append(string.Format(linkbtn_template, "export", "icon-user_go", permissionExport ? "" : "disabled=\"True\"", "导出用户数据", "导出"));
            return sb.ToString();
        }

        private void BindGrid()
        {
            this.DTUser = base.GetUserScope(this.PermissionItemScopeCode);
            //this.gvUserList.DataSource = this.DTUser;
            //this.gvUserList.DataBind();           
        }       
        

        /// <summary>
        /// 获得权限
        /// </summary>
        private void GetPermission()
        { 
            this.permissionAdd = this.IsAuthorized("UserManagement.Add");
            this.permissionEdit = this.IsAuthorized("UserManagement.Edit");
            this.permissionSetPassword = this.IsAuthorized("UserManagement.SetUserPassword");
            this.permissionDelete = this.IsAuthorized("UserManagement.Delete");
        }

    }
}